using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Winter.BackEnd.Models.Domain;

namespace Winter.BackEnd.Controllers
{
    public class SubjectsController : ApplicationController
    {
        public ActionResult Index()
        {
            List<SelectListItem> subjectTypes = new List<SelectListItem>();

            Array.ForEach(Repository.GetParameterValuesByParamenterName(Constants.SubjectType).ToArray(), (subjectType) =>
            {
                subjectTypes.Add(new SelectListItem()
                {
                    Value = subjectType.ID.ToString(),
                    Text = subjectType.Caption
                });
            });

            ViewData["SubjectType"] = subjectTypes;
            return View();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult GetScheduleHourPerWeek()
        {
            JsonResult result = new JsonResult();

            var rows = from timeBoard in Repository.CurrentDataContext.TimeBoards
                       select new
                       {
                           SubjectName = timeBoard.Subject.Name,
                           FirstTerm = timeBoard.FirstTerm,
                           SecondTerm = timeBoard.SecondTerm,
                           ThirdTerm = timeBoard.ThirdTerm,
                           FourthTerm = timeBoard.FourthTerm,
                           FifthTerm = timeBoard.FifthTerm,
                           SixthTerm = timeBoard.SixthTerm,
                           SeventhTerm = timeBoard.SeventhTerm,
                           EighthTerm = timeBoard.EighthTerm
                       };
            result.Data = new { page = 1, records = rows.Count(), rows, total = 1 };
            return result;
        }
    }
}
